import React, { useState } from 'react'
// import Div from '../Components/users/Login'
import { login } from '../services/admin';
import { useNavigate } from 'react-router-dom';
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import { Card } from 'antd';
export default function Login() {
    let navigate = useNavigate();

    const onFinish = async (values) => {
        // console.log('Received values of form: ', values);
        let res = await login({ username: values.username, pwd: values.password });
        alert(res.str);
        console.log(res);
        if (res.state == 1) {
            console.log(res);
            localStorage.setItem('token', res.token);
            navigate("/manage")
        }
    };

    return (
        <div style={{
            // width: '1000px',
            // padding: "30px",
            // background: "#ececec",
            // margin: "auto"
        }}>
            <Card title="登录" bordered={false} >
                <Form
                    name="normal_login"
                    className="login-form"
                    initialValues={{
                        remember: true,
                    }}
                    onFinish={onFinish}
                >
                    <Form.Item
                        name="username"
                        rules={[
                            {
                                required: true,
                                message: '请输入用户名!',
                            },
                        ]}
                    >
                        <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="用户名" />
                    </Form.Item>
                    <Form.Item
                        name="password"
                        rules={[
                            {
                                required: true,
                                message: '请输入密码!',
                            },
                        ]}
                    >
                        <Input
                            prefix={<LockOutlined className="site-form-item-icon" />}
                            type="password"
                            placeholder="密码"
                        />
                    </Form.Item>
                    <Form.Item>
                        <Form.Item name="remember" valuePropName="checked" noStyle>
                            <Checkbox>记住我</Checkbox>
                        </Form.Item>

                        <a className="login-form-forgot" href="">
                            忘记密码
                        </a>
                    </Form.Item>

                    <Form.Item>
                        <Button type="primary" htmlType="submit" className="login-form-button">
                            登录
                        </Button>
                    </Form.Item>
                </Form>
            </Card>
        </div>
    )
}

